function resetFormFields(el){
    var formEl = document.getElementById(el).elements;
    for (var x=0; x < formEl.length; x++) {
        switch(formEl[x].type){
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                formEl[x].value = '';
                break;
            case 'checkbox':
            case 'radio':
                formEl[x].checked = false;
                break;
            case 'selected':
                formEl[x].selected = false;
                break;
        }
    }
}

function formDateTimeStr(){
    d = new Date();
    var timeString = d.toLocaleString();
    $('.main_time').html(timeString);
}

function openDeleteDialog(url, delete_id){
    $("#delete").attr('src', url);
    $("#deleteDiv").dialog({
        width: 400,
        height: 180,
        modal: true,
        resizable: false,
        buttons: {
			"Proceed with deletion": function() {
                $.post(url, {'id' : delete_id}, function(data) {
                    $("#deleteDiv").dialog( "close" );
                });
			},
			Cancel: function() {
				$(this).dialog( "close" );
			}
		}
    });
    return false;
}

function openViewDialog(json_obj){
    var obj = JSON.parse(json_obj);

    if((!obj['titleHead'] || 0 === obj['titleHead'].length)){
        obj['titleHead'] = "Update Details";
    }
    if(!obj['widthParam'] || obj['widthParam'].length === 0 || obj['widthParam'] == 0){
        obj['widthParam'] = 750;
    }
    if(!obj['heightParam'] || obj['heightParam'].length === 0 || obj['heightParam'] == 0){
        obj['heightParam'] = 420;
    }

    $("#view").attr('src', obj['url']);
    $("#viewDiv").attr('title', obj['titleHead']);
    $("#viewDiv").dialog({
        width: obj['widthParam'],
        height: obj['heightParam'],
        modal: true,
        resizable: true
    });
    return false;
}

function openEditDialog(json_obj){

    var obj = JSON.parse(json_obj);

    if((!obj['titleHead'] || 0 === obj['titleHead'].length)){
        obj['titleHead'] = "Update Details";
    }
    if(!obj['widthParam'] || obj['widthParam'].length === 0 || obj['widthParam'] == 0){
        obj['widthParam'] = 750;
    }
    if(!obj['heightParam'] || obj['heightParam'].length === 0 || obj['heightParam'] == 0){
        obj['heightParam'] = 420;
    }

    $("#edit").attr('src', obj['url']);
    $("#editDiv").attr('title', obj['titleHead']);
    $("#editDiv").dialog({
        width  : obj['widthParam'],
        height : obj['heightParam'],
        modal  : true,
        resizable: false
    });
    return false;
}